package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.LuckDrawLog;
import com.juyu.miliao.common.dataSource.tool.operate.Operate;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: 卜加超
 * @Date: 2019/7/12 14:00
 * @Description:
 */
@Repository
public class LuckDrawDao {
    @Resource
    private SqlSession sqlSession;


    public int insertLuckDraw(LuckDrawLog luckDraw, Long userId) {

        return sqlSession.insert("saveLuckDraw",luckDraw);
    }

    public List<LuckDrawLog> getLuckDrawList(long userId) {
        return sqlSession.selectList("getLuckDrawList");
    }

    public List<LuckDrawLog> getLuckDrawListByUserId(long userId) {
        return sqlSession.selectList("getLuckDrawListByUserId",userId);
    }

    public LuckDrawLog getLuckDraw(long userId, int drawId) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("drawId", drawId);
        return sqlSession.selectOne("getLuckDraw",params);
    }

    public int updateLuckDrawStatus(long userId, int drawId) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("drawId", drawId);
        params.put("status", 4);
        params.put("reasonsFailure", "取消兑换奖品");
        return sqlSession.update("updateLuckDrawStatus",params);
    }
}
